package com.share.homestay.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.share.homestay.dao.SysUserMapper;
import com.share.homestay.entity.OrderLogs;
import com.share.homestay.entity.SysUser;
import com.share.homestay.entity.TjPermissions;
import com.share.homestay.pojo.JsonResult;
import com.share.homestay.service.SysUserService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {

    @Override
    public JsonResult sysUserPageQuery(SysUser sysUser, Integer pageNum, Integer pageSize) {
        return JsonResult.success("成功",this.baseMapper.sysUserPageQuery(sysUser,pageNum,pageSize),this.baseMapper.sysUserQueryCount(sysUser));
    }

    @Override
    public SysUser getUserByUsername(String username) {
        QueryWrapper<SysUser> qw = new QueryWrapper<>();
        qw.eq("user_name",username);
        List<SysUser> sysUsers = this.baseMapper.selectList(qw);
        return sysUsers.get(0);
    }

    @Override
    public List<TjPermissions> selectPermsByUserId(Long userId) {
        return this.baseMapper.selectPermsByUserId(userId);
    }

    @Override
    public void addOrderLogs(OrderLogs orderLogs) {
        this.baseMapper.addOrderLogs(orderLogs);
    }

    @Override
    public JsonResult selectLogs(OrderLogs orderLogs, Integer pageNum, Integer pageSize) {
        return JsonResult.success("成功",this.baseMapper.selectLogs(orderLogs, pageNum, pageSize),this.baseMapper.selectLogsCount(orderLogs));
    }

    @Override
    public List<SysUser> findAllUser() {
        return this.baseMapper.findAllUser();
    }

}
